package org.go.examples.example_15;

import org.go.examples.example_01.MyTask;
import org.go.scheduler.Scheduler;
import org.go.scheduler.StdSchedulerFactory;
import org.go.trigger.CronScheduleBuilder;
import org.go.trigger.Trigger;
import org.go.work.Work;
import org.go.work.WorkBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example_15 {
	private static Logger _log = LoggerFactory.getLogger(Example_15.class);

	public static void main(String[] args) throws Exception {
		// define the work and tie it to our MyTask class
		Work work = WorkBuilder.newWork(MyTask.class).withIdentity("job1", "group1").build();
		// Creates the scheduler.
		Scheduler scheduler = new StdSchedulerFactory().getScheduler("DefaultScheduler");
		// Schedules the task, once every 5 seconds.
		String cron = "*/5 * * * * ?";
		Trigger cronTrigger = CronScheduleBuilder.cronSchedule(cron).build();
		_log.info("------- Starting Scheduler ---------------");
		scheduler.scheduler(work, cronTrigger);
		_log.info("------- Started Scheduler ----------------");

		_log.info("------- Waiting for one hour... ----------");
		try {
			Thread.sleep(3600L * 1000L);
		} catch (Exception e) {
		}

		_log.info("------- Shutting Down --------------------");
		scheduler.shutdownNow();
		_log.info("------- Shutdown Complete ----------------");
	}
}
